<template>
    <div class="app-container">
        <h1>{{attraction.name}}</h1>
        <el-divider></el-divider>
        <el-form label-width="80px"  class="order-form">
            <el-form-item label="用户名"  >
                <el-input type="text" label="用户名" v-model="username" disabled></el-input>
            </el-form-item>
            <el-form-item label="出行人数">
                <el-input type="number" label="出行人数" v-model="form.count"></el-input>
            </el-form-item>
            <el-form-item label="联系方式">
                <el-input type="phone" label="联系方式" v-model="form.phone"></el-input>
            </el-form-item>
            <el-form-item label="类型">
                <el-radio v-model="form.type" label="0">成人</el-radio>
                <el-radio v-model="form.type" label="1">儿童</el-radio>
            </el-form-item>
            <el-form-item label="预约时间">
                <el-date-picker type="datetime" placeholder="选择日期" v-model="form.travelTime" value-format="yyyy-MM-dd HH:mm:ss"></el-date-picker>
            </el-form-item>
            <el-form-item label="备注">
                <el-input type="textarea" placeholder="请输入内容" v-model="form.desc">
                </el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="warning" @click="onSubmit">立即购买</el-button>
                <el-button type="warning" @click="onCancel" plain>取消</el-button>
            </el-form-item>
        </el-form>


    </div>
</template>
 
<script>
import { mapGetters } from 'vuex'
import { addOrder } from '@/api/order'

export default {
    name: 'Order',
    computed: {
        ...mapGetters([
            'userinfo'
        ])
    },
    created() {
        console.log(this.$route.params.attraction)
        this.attraction = this.$route.params.attraction
        this.form.attrId = this.attraction.attrId
        console.log(this.userinfo)
        this.username = this.userinfo.username
        
    },
    data() {
        return {
            form: {},
            username: '',
            attraction: null,
        }
    },
    methods: {
        async onSubmit() {
            console.log(this.form)
            let res = await addOrder(this.form)
            if (res.code === 200) {
                this.$message.success('购买成功')
                this.$router.push({path:'/orderSuccess', query: {attrId: this.attraction.attrId}})
            } else {
                this.$message.error('错误')
            }
            
        },
        onCancel() {
            // this.$router.push({path:'/orderSuccess'})
            this.$router.go(-1)
        },

    }
}
</script>
 
<style lang="less" scoped>
.app-container {
    width: 1000px;
    margin: 0 auto;

    .order-form {
        width: 400px;
        margin-bottom: 20px;
    }


}
</style>